package homework3;

import java.util.Scanner;

//猜数字游戏
public class P4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //获取[a,b]区间的随机数，公式如下
        //[0 ,1) * (b - a + 1) + a ->-> [0 ,b-a+1) +a ->-> [a ,b+1)
        int rnd = (int) (Math.random() * (100 - 1 + 1) + 1);
        System.out.println("请输入你要猜的值:");
        while (sc.hasNextInt()){
            int n = sc.nextInt();
            if (n > rnd)
                System.out.println("猜大了!");
            else if (n < rnd)
                System.out.println("猜小了!");
            else{
                System.out.println("恭喜你,猜对了!");
                break;
            }

        }
        sc.close();
    }
}
